function SourceUtils() {
	this.getProp = getProp;
	this.setPropInVersion = setPropInVersion;
	this.setCapablities = setCapablities;
	this.getOriginalDataSourceUri = getOriginalDataSourceUri;
	this.getQueryUriFromCaps=getQueryUriFromCaps;
	this.displaySourcesDetails=displaySourcesDetails;

	function getProp(propName, version) {
		var props = version.prop;
		for ( var i = 0; i < props.length; i++) {
			if (propName == props[i].name) {
				return props[i].value;
			}

		}
	}
	;

	function setPropInVersion(propName, propValue, version) {
		var props = version.prop;
		for ( var i = 0; i < props.length; i++) {
			if (propName == props[i].name) {
				props[i].value = propValue;
			}

		}
	}
	;

	function setCapablities(capabilityTypes, version, rootUri) {

		var newCaps = [];
		

		for ( var i = 0; i < capabilityTypes.length; i++) {
			var queryUri = getQueryUriForType(capabilityTypes[i], rootUri);
			var cap='';
			if(queryUri!=''){
				cap = {
						"type" : capabilityTypes[i],
						"queryUri" : queryUri
					};
			}else{
				cap = {
						"type" : capabilityTypes[i]
					};	
			}
			
			// alert(cap);
			newCaps.push(cap);
			version.capability = newCaps;
		}

	}

	function getQueryUriForType(capabilityType, rootUri) {
		//add the command queryUri if one of these capabilities
		var commandArray=['das1:sources', 'das1:features', 'das1:structure', 'das1:stylesheet', 'das1:types', 'das1:dsn', 'das1:entry_points', 'das1:alignment','das1:interaction', 'das1:sequence'];
		var queryUri='';
		for(var i=0;i<commandArray.length;i++){
		if(capabilityType==commandArray[i]){
			//chop off the das1: bit for the queryuri
			queryUri = rootUri+"/"+capabilityType.substring(capabilityType.indexOf(':')+1,capabilityType.length);
			return queryUri;
		}	
		
		}
		
		
	}

	function getOriginalDataSourceUri(capability) {
		var queryUri='';
		if (capability != undefined) {
			queryUri = getQueryUriFromCaps(capability);	
			//alert('q uri set '+queryUri);
		} else {
			return 'no capabilities for this source and version defined';
		}
		//alert(queryUri);
		var dasString = "/das/";
		var dasIndex = queryUri.indexOf(dasString);
		//alert("dasIndex=" + dasIndex);
		if (dasIndex == -1) {
			dasString = "/das1/";
			dasIndex = queryUri.indexOf(dasString);
		}
		// if (this.hasBigFileFormat()) {
		// return queryUri;
		// }
		if (dasIndex == -1) {
			//assume this is a bigbam or bigfile queryuri so just return it
			return queryUri;
			//alert("the das source query_uri must contain a /das/ queryUri="
					//+ queryUri);
			
		}
		var includingDAS = queryUri.substring(0, dasIndex + dasString.length);
		var afterDas = queryUri.substring(dasIndex + dasString.length,
				queryUri.length);
		var sourceUri = "";
		if (afterDas.indexOf("/")!=0) {
			sourceUri = includingDAS
					+ afterDas.substring(0, afterDas.indexOf("/"));
		} else {
			sourceUri = includingDAS + afterDas;
		}
		 //alert("sourceUri="+sourceUri);
		return sourceUri;

	}
	
	function getQueryUriFromCaps(capList){
		for(var i=0;i<capList.length;i++){
			if((capList[i].queryUri!=undefined) && (capList[i].queryUri!="")){
				//alert(capList[i].queryUri);
				return capList[i].queryUri;
			}
		}
		return "";
	}

	//display a sources response from the server in detail, usually one source for the details page
	//example request would be url http://www.dasregistry.org/das/sources/DS_114
	function displaySourcesDetails(sources){
		//maybe we should use html more and just javascript to populate the tables
		var html='';
		for(var i=0;i<sources.source.length;i++){
			var source=sources.source[i];
			html+=source.uri;
			
		}
		alert(html);
		return html;
		
	}
};